package com.qijian.flowable.controller;

import java.util.List;
import lombok.RequiredArgsConstructor;
import com.qijian.common.utils.mybatis.WhereEntityTool;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qijian.common.annotation.Log;
import com.qijian.common.core.controller.BaseController;
import com.qijian.common.core.domain.AjaxResult;
import com.qijian.common.enums.BusinessType;
import com.qijian.flowable.domain.FlowableRuleDetail;
import com.qijian.flowable.domain.query.FlowableRuleDetailQuery;
import com.qijian.flowable.service.IFlowableRuleDetailService;
import com.qijian.common.utils.poi.ExcelUtil;
import com.qijian.common.core.page.TableDataInfo;

/**
 * 流程规则明细Controller
 *
 * @author qijian
 * @date 2021-09-17
 */
@Api(tags = "流程模块：流程规则明细")
@RestController
@RequiredArgsConstructor
@RequestMapping("/flowable/flowableRuleDetail")
public class FlowableRuleDetailController extends BaseController {

    private final IFlowableRuleDetailService flowableRuleDetailService;

    /**
     * 查询流程规则明细列表
     */
    @PreAuthorize("@ss.hasPermi('flowable:flowableRuleDetail:list')")
    @GetMapping("/list")
        public TableDataInfo list(FlowableRuleDetailQuery query, IPage<FlowableRuleDetail> page) {
        return getDataTable(flowableRuleDetailService.page(Page.of(page.getCurrent(), page.getSize()), WhereEntityTool.invoke(query)));
    }
    
    /**
     * 导出流程规则明细列表
     */
    @PreAuthorize("@ss.hasPermi('flowable:flowableRuleDetail:export')")
    @Log(title = "流程规则明细" , businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FlowableRuleDetailQuery query) {
        return new ExcelUtil<>(FlowableRuleDetail. class).exportExcel(flowableRuleDetailService.list( WhereEntityTool.invoke(query)), "流程规则明细数据");
    }

    /**
     * 获取流程规则明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('flowable:flowableRuleDetail:query')")
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId) {
        return AjaxResult.success(flowableRuleDetailService.getById(detailId));
    }

    /**
     * 新增流程规则明细
     */
    @PreAuthorize("@ss.hasPermi('flowable:flowableRuleDetail:add')")
    @Log(title = "流程规则明细" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlowableRuleDetail flowableRuleDetail) {
        return toAjax(flowableRuleDetailService.save(flowableRuleDetail));
    }

    /**
     * 修改流程规则明细
     */
    @PreAuthorize("@ss.hasPermi('flowable:flowableRuleDetail:edit')")
    @Log(title = "流程规则明细" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlowableRuleDetail flowableRuleDetail) {
        return toAjax(flowableRuleDetailService.updateById(flowableRuleDetail));
    }

    /**
     * 删除流程规则明细
     */
    @PreAuthorize("@ss.hasPermi('flowable:flowableRuleDetail:remove')")
    @Log(title = "流程规则明细" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable List<Long> detailIds) {
        return toAjax(flowableRuleDetailService.removeByIds(detailIds));
    }
}
